package cn.edu.sdjzu.xg.bysj.domain;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.logging.LogRecord;

@WebFilter(filterName = "Filter 0",urlPatterns = {"/*"})
public class EncodingFilter implements Filter {
    public void destroy(){}
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        System.out.println("Filter 0 - encoding begins");
        HttpServletRequest request1 = (HttpServletRequest) request;
        HttpServletResponse response1 = (HttpServletResponse) response;
        request.setCharacterEncoding("UTF-8");
//        response.setContentType("text/html;charset=UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        chain.doFilter(request,response);
        System.out.println("Filter 0 - encoding ends");
    }
    public void init(FilterConfig config) throws ServletException{}

}
